package com.zj.rocketmq.demo.service;

import com.zj.rocketmq.demo.entity.Goods;
import com.zj.rocketmq.demo.repository.GoodsRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
@Transactional
public class GoodsService {

    @Resource
    private GoodsRepository goodsRepository;

    public void decrement(Integer goodsId){
        goodsRepository.decrementOfGoods(goodsId);
    }

    public boolean haveStock(Integer goodsId){
        Goods byId = goodsRepository.getById(goodsId);
        return byId.getStock() > 0;
    }
}
